package com.canbot.u05.view;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.canbot.u05.R;

/**
 * Created by Administrator on 2017/3/10.
 */

public class CenterDialogCounsel extends Dialog {

        private Context mContext;

        private String mTitleText;

        private String mLeftBtnText;

        private String mRightBtnText;

        private TextView mTVMsg;

        private String mString;

        private IButtonClickListerner mClickListenerInterface;

        private final String TAG = "CenterDialog";

        /**
         * @param context
         * @param style
         * @param titleText      提示音的文本
         * @param leftBtnText    左边btn的文本
         * @param rightBtnText   右边btn的文本
         * @param IClickListener 点击事件的监听器
         */
        public CenterDialogCounsel(Context context, int style, String titleText,
                                   String leftBtnText, String rightBtnText, IButtonClickListerner IClickListener) {
                super(context, style);
                this.mContext = context;
                this.mTitleText = titleText;
                this.mLeftBtnText = leftBtnText;
                this.mRightBtnText = rightBtnText;
                this.mClickListenerInterface = IClickListener;
        }

        public CenterDialogCounsel(Context context, int style, String titleText,
                                   IButtonClickListerner IClickListener) {
                super(context, style);
                this.mContext = context;
                this.mTitleText = titleText;
                this.mClickListenerInterface = IClickListener;
        }

        @Override
        protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                initView();
        }

        private void initView() {
                LayoutInflater layoutInflater = LayoutInflater.from(mContext);
                View viewDialog = layoutInflater.inflate(R.layout.counsel_dialog_cell, null);
                setContentView(viewDialog);

                setCanceledOnTouchOutside(false);
                TextView mTextView = (TextView) viewDialog.findViewById(R.id.tv_dialogtext);
                Button mBtnLeft = (Button) viewDialog.findViewById(R.id.counsel_dialog_cancel);
                Button mBtnRight = (Button) viewDialog.findViewById(R.id.counsel_dialog_reconnection);
                mTextView.setText(mTitleText);
                mBtnLeft.setText(mRightBtnText);
                mBtnRight.setText(mLeftBtnText);
                mBtnLeft.setOnClickListener(new ClickListener());
                mBtnRight.setOnClickListener(new ClickListener());
        }


        @Override
        public void show() {
                super.show();
        }

        @Override
        public void cancel() {
                super.cancel();
        }

        private class ClickListener implements android.view.View.OnClickListener {

                @Override
                public void onClick(View v) {
                        cancel();
                        int viewID = v.getId();
                        switch (viewID) {
                                case R.id.counsel_dialog_reconnection:
                                        if (mClickListenerInterface != null) {
                                                mClickListenerInterface.doBtnRight();
                                        }
                                        break;
                                case R.id.counsel_dialog_cancel:
                                        if (mClickListenerInterface != null) {
                                                mClickListenerInterface.doBtnLeft();
                                        }
                                        break;
                                default:
                                        break;
                        }
                }

        }
}

